'''
@Project ：python-study
@File    ：9.10词云图：电影类型频数统计.py
@IDE     ：PyCharm
@Author  ：SUNLIN
@Date    ：2025/3/17 14:47:37
'''
import C8处理与分析.pandas_def as pdef
import numpy as np

import os
import re
from PIL import Image
from os import path
from wordcloud import WordCloud
import matplotlib.pyplot as plt

font_path = 'C:/Windows/Fonts/simhei.ttf'


def makeImage(text):
    alice_mask = np.array(Image.open("../doc/datasource/C9-9.10-mask.png"))
    wc = WordCloud(background_color="white", max_words=500, mask=alice_mask, font_path=font_path)
    # generate word cloud
    wc.generate_from_frequencies(text)
    # show
    plt.imshow(wc, interpolation="bilinear")
    plt.axis("off")
    plt.show()


if __name__ == '__main__':
    file_path = 'D:\develop\projects\Python Project\python-study\doc\datasource\C8-8.5-数据采集-clean.xlsx'
    # 获取数据：类型 - 频数
    data = pdef.type_tj(file_path).sort_values('统计', ascending=False)
    keys = data.index.tolist()
    values = data['统计'].tolist()
    dic = dict(zip(keys, values))
    print(dic)
    # 绘制词云图
    makeImage(dic)
